package argo.hot100.linklist;

public class SwapPairs {

    public ListNode swapPairs(ListNode head) {
        ListNode nh = new ListNode(0);
        nh.next = head;

        ListNode p1, p2, p0 = nh;
        while (p0.next != null && p0.next.next != null) {
            p1 = p0.next.next;
            p2 = p0.next;

            p0.next = p1;
            p2.next = p1.next;
            p1.next = p2;

            p0 = p2;
        }

        return nh.next;
    }
}
